<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>课程辅导-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	    	<h1 class="weui-header-title">学生课程辅导记录</h1>
	    </div>
	</div>
	<div style="height: 36px;"></div>
	<div class="weui_panel weui_panel_access" style="margin-bottom: 55px;">
    	<div class="weui_panel_bd moments" id="coachList"></div>
    </div>
		<script id="classCoach-table-template" type="text/x-handlebars-template">
			{{#each rows}}
			<div class="weui_cells"  style="margin: 0 0 15px;">
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">姓名</div>
					<div class="weui_cell_bd weui_cell_primary tr">
						<p>{{studentName}}  {{gradeText}}（{{clazz}}）班</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">辅导类型</div>
					<div class="weui_cell_bd weui_cell_primary tr">
						<p>{{coachTypeText}}</p>
					</div>
				</div>				
				{{#equal coachType 1}}
					<div class="weui_cell">
						<div class="weui_cell_hd" style="width: 120px;">请假时间</div>
						<div class="weui_cell_bd weui_cell_primary tr">
							<p>{{twoDateFormat leaveStartTime leaveEndTime}}</p>
						</div>
					</div>
					<div style="border-top: 1px solid #d9d9d9">
						<div class="weui_cell">
							<div class="weui_cell_hd f-blue" style="width: 120px;">课程</div>
							<div class="weui_cell_bd weui_cell_primary tr">
								辅导情况
							</div>
						</div>
						{{#each coachList}}
							<div class="weui_cell downSlide">
								<div class="weui_cell_hd" style="width: 120px;">{{subject}}</div>
								<div class="weui_cell_bd weui_cell_primary tr">
									{{#coachStatusFormat coachStatus}}{{/coachStatusFormat}}
								</div>
							</div>
							{{#equal coachStatus 000}}
							<div class="downSlide-content" style="background-color: #F8F8F8;padding-bottom: 10px; display: none;">
								<div class="weui_cell">
									<div class="weui_cell_bd" style="width:120px;">
										<p>辅导教师</p>
									</div>
									<div class="weui_cell_ft f-black"> {{teacherName}} </div>
								</div>
								<div class="weui_cell">
									<div class="weui_cell_bd" style="width:120px;">
										<p>辅导时间</p>
									</div>
									<div class="weui_cell_ft f-black">
										<p>{{dateFormat coachTime}}</p>
									</div>
								</div>
								<div class="weui_cell">
									<div class="weui_cell_ft f-black" style="text-align: left;line-height: 1.3em;"> 
										<span class="f17">辅导详情:</span> {{coachResult}}
									</div>
								</div>
							</div>
							{{/equal}}
						{{/each}}
					{{else}}
						<div class="weui_cell">
							<div class="weui_cell_hd" style="width: 120px;">辅导状态</div>
							<div class="weui_cell_bd weui_cell_primary tr">
								<p style="color:#18b4ed">已辅导</p>
							</div>
						</div>
						<div class="weui_cell">
							<div class="weui_cell_hd" style="width: 120px;">辅导课程</div>
							<div class="weui_cell_bd weui_cell_primary tr">
								<p>{{subject}}</p>
							</div>
						</div>
						<div class="weui_cell">
							<div class="weui_cell_hd" style="width: 120px;">辅导老师</div>
							<div class="weui_cell_bd weui_cell_primary tr">
								<p>{{teacherName}}</p>
							</div>
						</div>
						<div class="weui_cell">
							<div class="weui_cell_hd" style="width: 120px;">辅导时间</div>
							<div class="weui_cell_bd weui_cell_primary tr">
								<p>{{dateFormat coachTime}}</p>
							</div>
						</div>
						<div class="weui_cell kcfd-listDetail">
							<div class="weui_cell_bd weui_cell_primary f15" style="line-height: 1.3em;">
								<p><span class="f17">辅导详情：</span>{{coachResult}}</p>
							</div>
						</div>
					{{/equal}}
				</div>
			</div>
			{{/each}}
		</script>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	$(function() {
		loadCoach()
	});
	
	function loadCoach() {
		//页数 
	    var page = 0;
	    // 每页展示5个
	    var size =5;
	    $('.weui_panel').dropload({
	        scrollArea : window,
	        autoLoad : true,//自动加载
	        domUp : {//下拉
	            domClass   : 'dropload-up',
	            domRefresh : '<div class="dropload-refresh"><i class="icon icon-114"></i>上拉加载更多</div>',
	            domUpdate  : '<div class="dropload-load f15"><i class="icon icon-20"></i>释放更新...</div>',
	            domLoad    : '<div class="dropload-load f15"><span class="weui-loading"></span>正在加载中...</div>'
	        },
	        loadDownFn : function(me){//加载更多
		        page++;
				window.params = {
					page: page,
		  	 		rows: size
				};	            
		       	$.ajax({
		          	url : basePath + "/xs/course/coach/page/query",
		  	 		type : "post",
		  	 		dataType : "json",
		  	 		data : window.params,
		            success: function(data){
		         		 if(data.rows.length == 0 || window.params.page*window.params.rows >= data.total) {// 如果没有数据
		                      // 锁定
		                      me.lock();
		                      // 无数据
		                      me.noData();
		                  }
		                  // 为了测试，延迟1秒加载
		                  setTimeout(function(){
		                	loadClassCoachHtml(data);
		                    // 每次数据加载完，必须重置
		                     me.resetload();
		                  },200);
		              },
		              error: function(xhr, type){
		              }
		          });
	        }
	    });
	}
	
	function loadClassCoachHtml(data, reload){
		var myTemplate = Handlebars.compile($("#classCoach-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
			if(v1 == v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		Handlebars.registerHelper("coachStatusFormat", function(v1,options) {
			if(v1 == '000') return "已辅导 <i class=\"icon icon-74\"></i>";
			if(v1 == '001') return "待辅导";
			if(v1 == '002') return "无需辅导";
			return "";
		});
		Handlebars.registerHelper("twoDateFormat", function(v1, v2) {
			return getTime(v1, "MM/dd hh:mm") + "-" + getTime(v2, "MM/dd hh:mm");
		});
		Handlebars.registerHelper("dateFormat", function(v1) {
			return getTime(v1, "yyyy/MM/dd hh:mm");
		});
		$('#coachList').append(myTemplate(data));
		
		$(".downSlide").click(function(){
			var obj = $(this);
			if(obj.hasClass("on")){
				obj.removeClass("on");
				obj.find(".icon").removeClass("icon-35").addClass("icon-74");
				obj.next(".downSlide-content").hide();
			}else{
				obj.addClass("on");
				obj.find(".icon").removeClass("icon-74").addClass("icon-35");
				obj.next(".downSlide-content").show();
			}
		});
	}
</script>

</body>
</html>